﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace StoryCardLogic.ImportExportData
{
    public class XmlStoryLoader : IStoryLoader
    {
        public readonly IFile FileManager;
        public readonly IStoryManager StoryManager;

        public XmlStoryLoader(IFile fileManager, IStoryManager storyManager)
        {
            FileManager = fileManager;
            StoryManager = storyManager;
        }

        public List<Story> Load(string path)
        {
            var serializer = new XmlSerializer(typeof(List<Story>));
            var readFromFile = FileManager.ReadFromFile(path);
            var reader = new StringReader(readFromFile);
            StoryManager.Stories = (List<Story>)serializer.Deserialize(reader);
            return StoryManager.Stories;
        }
    }
}